﻿//************************************************************************************************
// Copyright © 2003-2012 Steven M. Cohn. All Rights Reserved.
//
// Facility:	Microsoft Development Environment 2012  Version 11.0.50727.1
// Environment:	Microsoft .NET Framework 4.5            Version v4.0.30319
//
// Description: Presents a search dialog box
//
// Revision History:
// -Who--------------- -When---------- -What------------------------------------------------------
// Steven M. Cohn		18-Oct-2003		New
// Steven M. Cohn		20-Nov-2012		Refresh! VS2010 .NET 4.5 64-bit
//************************************************************************************************

namespace CookieChipper
{
	using System;
	using System.Windows.Forms;


	/// <summary>
	/// Presents a search dialog box
	/// </summary>
	
	internal partial class SearchBox : OptionalForm
	{

		/// <summary>
		/// 
		/// </summary>

		public SearchBox ()
		{
			InitializeComponent();
		}


		/// <summary>
		/// 
		/// </summary>
		/// <param name="text"></param>
		/// <param name="forward"></param>

		public delegate void SearchHandler (string text, bool forward);


		/// <summary>
		/// 
		/// </summary>

		public event SearchHandler Search;


		/// <summary>
		/// 
		/// </summary>

		public string SearchPhrase
		{
			set { textBox.Text = value; }
		}


		private void DoFindNext (object sender, EventArgs e)
		{
			if (Search != null)
			{
				Search(textBox.Text, (Control.ModifierKeys & Keys.Shift) == 0);
			}
		}


		private void DoFindPrevious (object sender, EventArgs e)
		{
			if (Search != null)
			{
				Search(textBox.Text, false);
			}
		}

	
		private void DoTextChanged (object sender, EventArgs e)
		{
			bool something = !String.IsNullOrWhiteSpace(textBox.Text);

			nextButton.Enabled = something;
			prevButton.Enabled = something;
		}
	}
}
